home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.3 (Developer)…68k, x86, SPARC, PA-RISC] / NeXTSTEP 3.3 Dev Intel.iso / NextDeveloper / Source / GNU / cc / fixinc.svr4 < prev    next >
Text File  |  1993-12-02  |  35KB  |  1,384 lines

  1. #! /bin/sh
  2. #
  3. #   fixinc.svr4  --  Install modified versions of certain ANSI-incompatible
  4. #   native System V Release 4 system include files.
  5. #
  6. #   Written by Ron Guilmette (rfg@ncd.com).
  7. #
  8. # This file is part of GNU CC.
  9. # GNU CC is free software; you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License as published by
  11. # the Free Software Foundation; either version 2, or (at your option)
  12. # any later version.
  13. # GNU CC is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. # GNU General Public License for more details.
  17. # You should have received a copy of the GNU General Public License
  18. # along with GNU CC; see the file COPYING.  If not, write to
  19. # the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  20. #
  21. #    This script munges the native include files provided with System V
  22. #    Release 4 systems so as to remove things which are violations of the
  23. #    ANSI C standard.  Once munged, the resulting new system include files
  24. #    are placed in a directory that GNU C will search *before* searching
  25. #    the /usr/include directory. This script should work properly for most
  26. #    System V Release 4 systems.  For other types of systems, you should
  27. #    use the `fixincludes' script instead.
  28. #
  29. #    See README-fixinc for more information.
  30.  
  31. # Directory where gcc sources (and sometimes special include files) live.
  32. SRCDIR=${3-${SRCDIR-.}}
  33.  
  34. # Directory containing the original header files.
  35. INPUT=${2-${INPUT-/usr/include}}
  36.  
  37. # Fail if no arg to specify a directory for the output.
  38. if [ x$1 = x ]
  39. then echo fixincludes: no output directory specified
  40. exit 1
  41. fi
  42.  
  43. # Directory in which to store the results.
  44. LIB=${1?"fixincludes: output directory not specified"}
  45.  
  46. # Make sure it exists.
  47. if [ ! -d $LIB ]; then
  48.   mkdir $LIB || exit 1
  49. fi
  50.  
  51. ORIG_DIR=`pwd`
  52.  
  53. # Make LIB absolute if it is relative.
  54. # Don't do this if not necessary, since may screw up automounters.
  55. case $LIB in
  56. /*)
  57.     ;;
  58. *)
  59.      LIB=$ORIG_DIR/$LIB
  60.     ;;
  61. esac
  62.  
  63. echo 'Building fixincludes in ' ${LIB}
  64.  
  65. # Determine whether this filesystem has symbolic links.
  66. if ln -s X $LIB/ShouldNotExist 2>/dev/null; then
  67.   rm -f $LIB/ShouldNotExist
  68.   LINKS=true
  69. else
  70.   LINKS=false
  71. fi
  72.  
  73. echo 'Making directories:'
  74. cd ${INPUT}
  75. if $LINKS; then
  76.   files=`ls -LR | sed -n s/:$//p`
  77. else
  78.   files=`find . -type d -print | sed '/^.$/d'`
  79. fi
  80. for file in $files; do
  81.   rm -rf $LIB/$file
  82.   if [ ! -d $LIB/$file ]
  83.   then mkdir $LIB/$file
  84.   fi
  85. done
  86.  
  87. # treetops gets an alternating list
  88. # of old directories to copy
  89. # and the new directories to copy to.
  90. treetops="${INPUT} ${LIB}"
  91.  
  92. if $LINKS; then
  93.   echo 'Making internal symbolic directory links'
  94.   for file in $files; do
  95.     dest=`ls -ld $file | sed -n 's/.*-> //p'`
  96.     if [ "$dest" ]; then    
  97.       cwd=`pwd`
  98.       # In case $dest is relative, get to $file's dir first.
  99.       cd ${INPUT}
  100.       cd `echo ./$file | sed -n 's&[^/]*$&&p'`
  101.       # Check that the target directory exists.
  102.       # Redirections changed to avoid bug in sh on Ultrix.
  103.       (cd $dest) > /dev/null 2>&1
  104.       if [ $? = 0 ]; then
  105.     cd $dest
  106.     # X gets the dir that the link actually leads to.
  107.     x=`pwd`
  108.     # If link leads back into ${INPUT},
  109.     # make a similar link here.
  110.     if expr $x : "${INPUT}/.*" > /dev/null; then
  111.       # Y gets the actual target dir name, relative to ${INPUT}.
  112.       y=`echo $x | sed -n "s&${INPUT}/&&p"`
  113.       # DOTS is the relative path from ${LIB}/$file's dir back to ${LIB}.
  114.       dots=`echo "$file" |
  115.         sed -e 's@^./@@' -e 's@/./@/@g' -e 's@[^/][^/]*@..@g' -e 's@..$@@'`
  116.       echo $file '->' $dots$y ': Making link'
  117.       rm -fr ${LIB}/$file > /dev/null 2>&1
  118.       ln -s $dots$y ${LIB}/$file > /dev/null 2>&1
  119.     else
  120.       # If the link is to outside ${INPUT},
  121.       # treat this directory as if it actually contained the files.
  122. # This line used to have $dest instead of $x.
  123. # $dest seemed to be wrong for links found in subdirectories
  124. # of ${INPUT}.  Does this change break anything?
  125.       treetops="$treetops $x ${LIB}/$file"
  126.     fi
  127.       fi
  128.       cd $cwd
  129.     fi
  130.   done
  131. fi
  132.  
  133. set - $treetops
  134. while [ $# != 0 ]; do
  135.   # $1 is an old directory to copy, and $2 is the new directory to copy to.
  136.   echo "Finding header files in $1:"
  137.   cd ${INPUT}
  138.   cd $1
  139.   files=`find . -name '*.h' -type f -print`
  140.   echo 'Checking header files:'
  141.   for file in $files; do
  142.       if [ -r $file ]; then
  143.     cp $file $2/$file >/dev/null 2>&1 || echo "Can't copy $file"
  144.     chmod +w $2/$file
  145.     chmod a+r $2/$file
  146.  
  147. # The following have been removed from the sed command below
  148. # because it is more useful to leave these things in.
  149. # The only reason to remove them was for -pedantic,
  150. # which isn't much of a reason. -- rms.
  151. #      /^[     ]*#[     ]*ident/d
  152.  
  153. # This code makes Solaris SCSI fail, because it changes the
  154. # alignment within some critical structures.  See <sys/scsi/impl/commands.h>.
  155. #      s/u_char\([     ][     ]*[a-zA-Z0-9_][a-zA-Z0-9_]*[     ]*:[     ]*[0-9][0-9]*\)/u_int\1/
  156. # Disable these also, since they probably aren't safe either.
  157. #      s/u_short\([     ][     ]*[a-zA-Z0-9_][a-zA-Z0-9_]*[     ]*:[     ]*[0-9][0-9]*\)/u_int\1/
  158. #      s/ushort\([     ][     ]*[a-zA-Z0-9_][a-zA-Z0-9_]*[     ]*:[     ]*[0-9][0-9]*\)/u_int\1/
  159. #      s/evcm_t\([     ][     ]*[a-zA-Z0-9_][a-zA-Z0-9_]*[     ]*:[     ]*[0-9][0-9]*\)/u_int\1/
  160. #      s/Pbyte\([     ][     ]*[a-zA-Z0-9_][a-zA-Z0-9_]*[     ]*:[     ]*SEQSIZ\)/unsigned int\1/
  161.  
  162. # The change of u_char, etc, to u_int
  163. # applies to bit fields.
  164.     sed -e '
  165.       s%^\([     ]*#[     ]*else\)[     ]*/[^*].*%\1%
  166.       s%^\([     ]*#[     ]*else\)[     ]*[^/     ].*%\1%
  167.       s%^\([     ]*#[     ]*endif\)[     ]*/[^*].*%\1%
  168.       s%^\([     ]*#[     ]*endif\)[     ]*[^/     ].*%\1%
  169.         s/#lint(on)/defined(lint)/g
  170.         s/#lint(off)/!defined(lint)/g
  171.         s/#machine(\([^)]*\))/defined(__\1__)/g
  172.         s/#system(\([^)]*\))/defined(__\1__)/g
  173.         s/#cpu(\([^)]*\))/defined(__\1__)/g
  174.       /#[a-z]*if.*[     (]m68k/        s/\([^_]\)m68k/\1__m68k__/g
  175.       /#[a-z]*if.*[     (]__i386\([^_]\)/    s/__i386/__i386__/g
  176.       /#[a-z]*if.*[     (]i386/        s/\([^_]\)i386/\1__i386__/g
  177.       /#[a-z]*if.*[     (]sparc/    s/\([^_]\)sparc/\1__sparc__/g
  178.       /#[a-z]*if.*[     (]mc68000/    s/\([^_]\)mc68000/\1__mc68000__/g
  179.       /#[a-z]*if.*[     (]vax/        s/\([^_]\)vax/\1__vax__/g
  180.       /#[a-z]*if.*[     (]sun/        s/\([^_]\)\(sun[a-z0-9]*\)\([^a-z0-9_]\)/\1__\2__\3/g
  181.       /#[a-z]*if.*[     (]sun/        s/\([^_]\)\(sun[a-z0-9]*\)$/\1__\2__/g
  182.       /#[a-z]*if.*[     (]ns32000/    s/\([^_]\)ns32000/\1__ns32000__/g
  183.       /#[a-z]*if.*[     (]pyr/        s/\([^_]\)pyr/\1__pyr__/g
  184.       /#[a-z]*if.*[     (]is68k/    s/\([^_]\)is68k/\1__is68k__/g
  185.       s/__STDC__[     ][     ]*==[     ][     ]*0/!defined (__STRICT_ANSI__)/g
  186.       s/__STDC__[     ][     ]*==[     ][     ]*1/defined (__STRICT_ANSI__)/g
  187.       s/__STDC__[     ][     ]*!=[     ][     ]*0/defined (__STRICT_ANSI__)/g
  188.       s/__STDC__ - 0 == 0/!defined (__STRICT_ANSI__)/g
  189.     ' $2/$file > $2/$file.sed
  190.     mv $2/$file.sed $2/$file
  191.     if cmp $file $2/$file >/dev/null 2>&1; then
  192.        rm $2/$file
  193.     else
  194.        echo Fixed $file
  195.     fi
  196.       fi
  197.   done
  198.   shift; shift
  199. done
  200.  
  201. # Fix first broken decl of getcwd present on some svr4 systems.
  202.  
  203. file=stdlib.h
  204. base=`basename $file`
  205. if [ -r ${LIB}/$file ]; then
  206.   file_to_fix=${LIB}/$file
  207. else
  208.   if [ -r ${INPUT}/$file ]; then
  209.     file_to_fix=${INPUT}/$file
  210.   else
  211.     file_to_fix=""
  212.   fi
  213. fi
  214. if [ \! -z "$file_to_fix" ]; then
  215.   echo Checking $file_to_fix
  216.   sed -e 's/getcwd(char \*, int)/getcwd(char *, size_t)/' $file_to_fix > /tmp/$base
  217.   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
  218.     true
  219.   else
  220.     echo Fixed $file_to_fix
  221.     rm -f ${LIB}/$file
  222.     cp /tmp/$base ${LIB}/$file
  223.     chmod a+r ${LIB}/$file
  224.   fi
  225.   rm -f /tmp/$base
  226. fi
  227.  
  228. # Fix second broken decl of getcwd present on some svr4 systems.  Also
  229. # fix the incorrect decl of profil present on some svr4 systems.
  230.  
  231. file=unistd.h
  232. base=`basename $file`
  233. if [ -r ${LIB}/$file ]; then
  234.   file_to_fix=${LIB}/$file
  235. else
  236.   if [ -r ${INPUT}/$file ]; then
  237.     file_to_fix=${INPUT}/$file
  238.   else
  239.     file_to_fix=""
  240.   fi
  241. fi
  242. if [ \! -z "$file_to_fix" ]; then
  243.   echo Checking $file_to_fix
  244.   sed -e 's/getcwd(char \*, int)/getcwd(char *, size_t)/' $file_to_fix \
  245.     | sed -e 's/profil(unsigned short \*, unsigned int, unsigned int, unsigned int)/profil(unsigned short *, size_t, int, unsigned)/' > /tmp/$base
  246.   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
  247.     true
  248.   else
  249.     echo Fixed $file_to_fix
  250.     rm -f ${LIB}/$file
  251.     cp /tmp/$base ${LIB}/$file
  252.     chmod a+r ${LIB}/$file
  253.   fi
  254.   rm -f /tmp/$base
  255. fi
  256.  
  257. # Fix the definition of NULL in <sys/param.h> so that it is conditional
  258. # and so that it is correct for both C and C++.
  259.  
  260. file=sys/param.h
  261. base=`basename $file`
  262. if [ -r ${LIB}/$file ]; then
  263.   file_to_fix=${LIB}/$file
  264. else
  265.   if [ -r ${INPUT}/$file ]; then
  266.     file_to_fix=${INPUT}/$file
  267.   else
  268.     file_to_fix=""
  269.   fi
  270. fi
  271. if [ \! -z "$file_to_fix" ]; then
  272.   echo Checking $file_to_fix
  273.   cp $file_to_fix /tmp/$base
  274.   chmod +w /tmp/$base
  275.   chmod a+r /tmp/$base
  276.   sed -e '/^#define[     ]*NULL[     ]*0$/c\
  277. #ifndef NULL\
  278. #ifdef __cplusplus\
  279. #define __NULL_TYPE\
  280. #else /* !defined(__cplusplus) */\
  281. #define __NULL_TYPE (void *)\
  282. #endif /* !defined(__cplusplus) */\
  283. #define NULL (__NULL_TYPE 0)\
  284. #endif /* !defined(NULL) */' /tmp/$base > /tmp/$base.sed
  285.   if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
  286.     true
  287.   else
  288.     echo Fixed $file_to_fix
  289.     rm -f ${LIB}/$file
  290.     cp /tmp/$base.sed ${LIB}/$file
  291.     chmod a+r ${LIB}/$file
  292.   fi
  293.   rm -f /tmp/$base /tmp/$base.sed
  294. fi
  295.  
  296. # Likewise fix the definition of NULL in <stdio.h> so that it is conditional
  297. # and so that it is correct for both C and C++.
  298.  
  299. file=stdio.h
  300. base=`basename $file`
  301. if [ -r ${LIB}/$file ]; then
  302.   file_to_fix=${LIB}/$file
  303. else
  304.   if [ -r ${INPUT}/$file ]; then
  305.     file_to_fix=${INPUT}/$file
  306.   else
  307.     file_to_fix=""
  308.   fi
  309. fi
  310. if [ \! -z "$file_to_fix" ]; then
  311.   echo Checking $file_to_fix
  312.   cp $file_to_fix /tmp/$base
  313.   chmod +w /tmp/$base
  314.   sed -e '/^#define[     ]*NULL[     ]*0$/c\
  315. #ifdef __cplusplus\
  316. #define __NULL_TYPE\
  317. #else /* !defined(__cplusplus) */\
  318. #define __NULL_TYPE (void *)\
  319. #endif /* !defined(__cplusplus) */\
  320. #define NULL (__NULL_TYPE 0)' /tmp/$base > /tmp/$base.sed
  321.   if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
  322.     true
  323.   else
  324.     echo Fixed $file_to_fix
  325.     rm -f ${LIB}/$file
  326.     cp /tmp/$base.sed ${LIB}/$file
  327.     chmod a+r ${LIB}/$file
  328.   fi
  329.   rm -f /tmp/$base /tmp/$base.sed
  330. fi
  331.  
  332. # Likewise fix the definition of NULL in <dbm.h> so that it is conditional
  333. # and so that it is correct for both C and C++.
  334.  
  335. file=dbm.h
  336. base=`basename $file`
  337. if [ -r ${LIB}/$file ]; then
  338.   file_to_fix=${LIB}/$file
  339. else
  340.   if [ -r ${INPUT}/$file ]; then
  341.     file_to_fix=${INPUT}/$file
  342.   else
  343.     file_to_fix=""
  344.   fi
  345. fi
  346. if [ \! -z "$file_to_fix" ]; then
  347.   echo Checking $file_to_fix
  348.   cp $file_to_fix /tmp/$base
  349.   chmod +w /tmp/$base
  350.   sed -e '/^#define[     ]*NULL[     ]*((char \*) 0)$/c\
  351. #ifndef NULL\
  352. #ifdef __cplusplus\
  353. #define __NULL_TYPE\
  354. #else /* !defined(__cplusplus) */\
  355. #define __NULL_TYPE (void *)\
  356. #endif /* !defined(__cplusplus) */\
  357. #define NULL (__NULL_TYPE 0)\
  358. #endif /* !defined(NULL) */' /tmp/$base > /tmp/$base.sed
  359.   if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
  360.     true
  361.   else
  362.     echo Fixed $file_to_fix
  363.     rm -f ${LIB}/$file
  364.     cp /tmp/$base.sed ${LIB}/$file
  365.     chmod a+r ${LIB}/$file
  366.   fi
  367.   rm -f /tmp/$base /tmp/$base.sed
  368. fi
  369.  
  370. # Add a prototyped declaration of mmap to <sys/mman.h>.
  371.  
  372. file=sys/mman.h
  373. base=`basename $file`
  374. if [ -r ${LIB}/$file ]; then
  375.   file_to_fix=${LIB}/$file
  376. else
  377.   if [ -r ${INPUT}/$file ]; then
  378.     file_to_fix=${INPUT}/$file
  379.   else
  380.     file_to_fix=""
  381.   fi
  382. fi
  383. if [ \! -z "$file_to_fix" ]; then
  384.   echo Checking $file_to_fix
  385.   cp $file_to_fix /tmp/$base
  386.   chmod +w /tmp/$base
  387.   sed -e '/^extern caddr_t mmap();$/c\
  388. #ifdef __STDC__\
  389. extern caddr_t mmap (caddr_t addr, size_t len, int prot, int flags,\
  390.                      int fd, off_t off);\
  391. #else /* !defined(__STDC__) */\
  392. extern caddr_t mmap ();\
  393. #endif /* !defined(__STDC__) */' /tmp/$base > /tmp/$base.sed
  394.   if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
  395.     true
  396.   else
  397.     echo Fixed $file_to_fix
  398.     rm -f ${LIB}/$file
  399.     cp /tmp/$base.sed ${LIB}/$file
  400.     chmod a+r ${LIB}/$file
  401.   fi
  402.   rm -f /tmp/$base /tmp/$base.sed
  403. fi
  404.  
  405. # Fix declarations of `ftw' and `nftw' in <ftw.h>.  On some/most SVR4 systems
  406. # the file <ftw.h> contains extern declarations of these functions followed
  407. # by explicitly `static' definitions of these functions... and that's not
  408. # allowed according to ANSI C.  (Note however that on Solaris, this header
  409. # file glitch has been pre-fixed by Sun.  In the Solaris version of <ftw.h>
  410. # there are no static definitions of any function so we don't need to do
  411. # any of this stuff when on Solaris.
  412.  
  413. file=ftw.h
  414. base=`basename $file`
  415. if [ -r ${LIB}/$file ]; then
  416.   file_to_fix=${LIB}/$file
  417. else
  418.   if [ -r ${INPUT}/$file ]; then
  419.     file_to_fix=${INPUT}/$file
  420.   else
  421.     file_to_fix=""
  422.   fi
  423. fi
  424. if test -z "$file_to_fix" || grep 'define    ftw' $file_to_fix > /dev/null; then
  425. # Either we have no <ftw.h> file at all, or else we have the pre-fixed Solaris
  426. # one.  Either way, we don't have to do anything.
  427.   true
  428. else
  429.   echo Checking $file_to_fix
  430.   cp $file_to_fix /tmp/$base
  431.   chmod +w /tmp/$base
  432.   sed -e '/^extern int ftw(const/i\
  433. #if !defined(_STYPES)\
  434. static\
  435. #else\
  436. extern\
  437. #endif'\
  438.   -e 's/extern \(int ftw(const.*\)$/\1/' \
  439.   -e '/^extern int nftw/i\
  440. #if defined(_STYPES)\
  441. static\
  442. #else\
  443. extern\
  444. #endif'\
  445.   -e 's/extern \(int nftw.*\)$/\1/' \
  446.   -e '/^extern int ftw(),/c\
  447. #if !defined(_STYPES)\
  448. static\
  449. #else\
  450. extern\
  451. #endif\
  452.   int ftw();\
  453. #if defined(_STYPES)\
  454. static\
  455. #else\
  456. extern\
  457. #endif\
  458.   int nftw();' /tmp/$base > /tmp/$base.sed
  459.   if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
  460.     true
  461.   else
  462.     echo Fixed $file_to_fix
  463.     rm -f ${LIB}/$file
  464.     cp /tmp/$base.sed ${LIB}/$file
  465.     chmod a+r ${LIB}/$file
  466.   fi
  467.   rm -f /tmp/$base /tmp/$base.sed
  468. fi
  469.  
  470. # Add a `static' declaration of `getrnge' into <regexp.h>.
  471.  
  472. # Don't do this if there is already a `static void getrnge' declaration
  473. # present, since this would cause a redeclaration error.  Solaris 2.x has
  474. # such a declaration.
  475.  
  476. file=regexp.h
  477. base=`basename $file`
  478. if [ -r ${LIB}/$file ]; then
  479.   file_to_fix=${LIB}/$file
  480. else
  481.   if [ -r ${INPUT}/$file ]; then
  482.     file_to_fix=${INPUT}/$file
  483.   else
  484.     file_to_fix=""
  485.   fi
  486. fi
  487. if [ \! -z "$file_to_fix" ]; then
  488.   echo Checking $file_to_fix
  489.   if grep "static void getrnge" $file_to_fix > /dev/null; then
  490.     true
  491.   else
  492.     cp $file_to_fix /tmp/$base
  493.     chmod +w /tmp/$base
  494.     sed -e '/^static int[     ]*size;/c\
  495. static int    size ;\
  496. \
  497. static int getrnge ();' /tmp/$base > /tmp/$base.sed
  498.     if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
  499.       true
  500.     else
  501.       echo Fixed $file_to_fix
  502.       rm -f ${LIB}/$file
  503.       cp /tmp/$base.sed ${LIB}/$file
  504.       chmod a+r ${LIB}/$file
  505.     fi
  506.   fi
  507.   rm -f /tmp/$base /tmp/$base.sed
  508. fi
  509.  
  510. # Disable apparent native compiler optimization cruft in SVR4.2 <string.h>
  511. # that is visible to any ANSI compiler using this include.  Simply
  512. # delete the lines that #define some string functions to internal forms.
  513.  
  514. file=string.h
  515. base=`basename $file`
  516. if [ -r ${LIB}/$file ]; then
  517.   file_to_fix=${LIB}/$file
  518. else
  519.   if [ -r ${INPUT}/$file ]; then
  520.     file_to_fix=${INPUT}/$file
  521.   else
  522.     file_to_fix=""
  523.   fi
  524. fi
  525. if [ \! -z "$file_to_fix" ]; then
  526.   echo Checking $file_to_fix
  527.   cp $file_to_fix /tmp/$base
  528.   chmod +w /tmp/$base
  529.   sed -e '/#define.*__std_hdr_/d' /tmp/$base > /tmp/$base.sed
  530.   if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
  531.     true
  532.   else
  533.     echo Fixed $file_to_fix
  534.     rm -f ${LIB}/$file
  535.     cp /tmp/$base.sed ${LIB}/$file
  536.     chmod a+r ${LIB}/$file
  537.   fi
  538.   rm -f /tmp/$base /tmp/$base.sed
  539. fi
  540.  
  541. # Delete any #defines of `__i386' which may be present in <ieeefp.h>.  They
  542. # tend to conflict with the compiler's own definition of this symbol.  (We
  543. # will use the compiler's definition.)
  544. # Likewise __sparc, for Solaris, and __i860, and a few others
  545. # (guessing it is necessary for all of them).
  546.  
  547. file=ieeefp.h
  548. base=`basename $file`
  549. if [ -r ${LIB}/$file ]; then
  550.   file_to_fix=${LIB}/$file
  551. else
  552.   if [ -r ${INPUT}/$file ]; then
  553.     file_to_fix=${INPUT}/$file
  554.   else
  555.     file_to_fix=""
  556.   fi
  557. fi
  558. if [ \! -z "$file_to_fix" ]; then
  559.   echo Checking $file_to_fix
  560.   cp $file_to_fix /tmp/$base
  561.   chmod +w /tmp/$base
  562.   sed -e '/#define[     ]*__i386 /d' -e '/#define[     ]*__sparc /d' \
  563.       -e '/#define[     ]*__i860 /d' -e '/#define[     ]*__m88k /d' \
  564.       -e '/#define[     ]*__mips /d' -e '/#define[     ]*__m68k /d' \
  565.      /tmp/$base > /tmp/$base.sed
  566.   if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
  567.     true
  568.   else
  569.     echo Fixed $file_to_fix 
  570.     rm -f ${LIB}/$file
  571.     cp /tmp/$base.sed ${LIB}/$file 
  572.     chmod a+r ${LIB}/$file
  573.   fi
  574.   rm -f /tmp/$base /tmp/$base.sed 
  575. fi 
  576.  
  577. # Add a #define of _SIGACTION_ into <sys/signal.h>.
  578. # Also fix types of SIG_DFL, SIG_ERR, SIG_IGN, and SIG_HOLD.
  579.  
  580. file=sys/signal.h
  581. base=`basename $file`
  582. if [ -r ${LIB}/$file ]; then
  583.   file_to_fix=${LIB}/$file
  584. else
  585.   if [ -r ${INPUT}/$file ]; then
  586.     file_to_fix=${INPUT}/$file
  587.   else
  588.     file_to_fix=""
  589.   fi
  590. fi
  591. if [ \! -z "$file_to_fix" ]; then
  592.   echo Checking $file_to_fix
  593.   cp $file_to_fix /tmp/$base
  594.   chmod +w /tmp/$base
  595.   sed -e '/^struct sigaction {/c\
  596. #define _SIGACTION_\
  597. struct  sigaction  {' \
  598.   -e '1,$s/(void *(\*)())/(void (*)(int))/' /tmp/$base > /tmp/$base.sed
  599.   if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
  600.     true
  601.   else
  602.     echo Fixed $file_to_fix
  603.     rm -f ${LIB}/$file
  604.     cp /tmp/$base.sed ${LIB}/$file
  605.     chmod a+r ${LIB}/$file
  606.   fi
  607.   rm -f /tmp/$base /tmp/$base.sed
  608. fi
  609.  
  610. # Fix declarations of `makedev', `major', and `minor' in <sys/mkdev.h>.
  611.  
  612. file=sys/mkdev.h
  613. base=`basename $file`
  614. if [ -r ${LIB}/$file ]; then
  615.   file_to_fix=${LIB}/$file
  616. else
  617.   if [ -r ${INPUT}/$file ]; then
  618.     file_to_fix=${INPUT}/$file
  619.   else
  620.     file_to_fix=""
  621.   fi
  622. fi
  623. if [ \! -z "$file_to_fix" ]; then
  624.   echo Checking $file_to_fix
  625.   cp $file_to_fix /tmp/$base
  626.   chmod +w /tmp/$base
  627.   sed -e '/^dev_t makedev(const/c\
  628. static dev_t makedev(const major_t, const minor_t);' \
  629.   -e '/^dev_t makedev()/c\
  630. static dev_t makedev();' \
  631.   -e '/^major_t major(const/c\
  632. static major_t major(const dev_t);' \
  633.   -e '/^major_t major()/c\
  634. static major_t major();' \
  635.   -e '/^minor_t minor(const/c\
  636. static minor_t minor(const dev_t);' \
  637.   -e '/^minor_t minor()/c\
  638. static minor_t minor();' /tmp/$base > /tmp/$base.sed
  639.   if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
  640.     true
  641.   else
  642.     echo Fixed $file_to_fix
  643.     rm -f ${LIB}/$file
  644.     cp /tmp/$base.sed ${LIB}/$file
  645.     chmod a+r ${LIB}/$file
  646.   fi
  647.   rm -f /tmp/$base /tmp/$base.sed
  648. fi
  649.  
  650. # Fix reference to NMSZ in <sys/adv.h>.
  651.  
  652. file=sys/adv.h
  653. base=`basename $file`
  654. if [ -r ${LIB}/$file ]; then
  655.   file_to_fix=${LIB}/$file
  656. else
  657.   if [ -r ${INPUT}/$file ]; then
  658.     file_to_fix=${INPUT}/$file
  659.   else
  660.     file_to_fix=""
  661.   fi
  662. fi
  663. if [ \! -z "$file_to_fix" ]; then
  664.   echo Checking $file_to_fix
  665.   sed 's/\[NMSZ\]/\[RFS_NMSZ\]/g' $file_to_fix > /tmp/$base
  666.   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
  667.     true
  668.   else
  669.     echo Fixed $file_to_fix
  670.     rm -f ${LIB}/$file
  671.     cp /tmp/$base ${LIB}/$file
  672.     chmod a+r ${LIB}/$file
  673.   fi
  674.   rm -f /tmp/$base
  675. fi
  676.  
  677. # Fix reference to NC_NPI_RAW in <sys/netcspace.h>.  Also fix types of
  678. # array initializers.
  679.  
  680. file=sys/netcspace.h
  681. base=`basename $file`
  682. if [ -r ${LIB}/$file ]; then
  683.   file_to_fix=${LIB}/$file
  684. else
  685.   if [ -r ${INPUT}/$file ]; then
  686.     file_to_fix=${INPUT}/$file
  687.   else
  688.     file_to_fix=""
  689.   fi
  690. fi
  691. if [ \! -z "$file_to_fix" ]; then
  692.   echo Checking $file_to_fix
  693.   sed 's/NC_NPI_RAW/NC_TPI_RAW/g' $file_to_fix \
  694.     | sed 's/NC_/(unsigned long) NC_/' > /tmp/$base
  695.   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
  696.     true
  697.   else
  698.     echo Fixed $file_to_fix
  699.     rm -f ${LIB}/$file
  700.     cp /tmp/$base ${LIB}/$file
  701.     chmod a+r ${LIB}/$file
  702.   fi
  703.   rm -f /tmp/$base
  704. fi
  705.  
  706. # Conditionalize all of <fs/rfs/rf_cache.h> on _KERNEL being defined.
  707.  
  708. file=fs/rfs/rf_cache.h
  709. base=`basename $file`
  710. if [ -r ${LIB}/$file ]; then
  711.   file_to_fix=${LIB}/$file
  712. else
  713.   if [ -r ${INPUT}/$file ]; then
  714.     file_to_fix=${INPUT}/$file
  715.   else
  716.     file_to_fix=""
  717.   fi
  718. fi
  719. if [ \! -z "$file_to_fix" ]; then
  720.   echo Checking $file_to_fix
  721.   if grep _KERNEL $file_to_fix > /dev/null; then
  722.     true
  723.   else
  724.     echo '#ifdef _KERNEL' > /tmp/$base
  725.     cat $file_to_fix >> /tmp/$base
  726.     echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
  727.     echo Fixed $file_to_fix
  728.     rm -f ${LIB}/$file
  729.     cp /tmp/$base ${LIB}/$file
  730.     chmod a+r ${LIB}/$file
  731.     rm -f /tmp/$base
  732.   fi
  733. fi
  734.  
  735. # Conditionalize all of <sys/erec.h> on _KERNEL being defined.
  736.  
  737. file=sys/erec.h
  738. base=`basename $file`
  739. if [ -r ${LIB}/$file ]; then
  740.   file_to_fix=${LIB}/$file
  741. else
  742.   if [ -r ${INPUT}/$file ]; then
  743.     file_to_fix=${INPUT}/$file
  744.   else
  745.     file_to_fix=""
  746.   fi
  747. fi
  748. if [ \! -z "$file_to_fix" ]; then
  749.   echo Checking $file_to_fix
  750.   if grep _KERNEL $file_to_fix > /dev/null; then
  751.     true
  752.   else
  753.     echo '#ifdef _KERNEL' > /tmp/$base
  754.     cat $file_to_fix >> /tmp/$base
  755.     echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
  756.     echo Fixed $file_to_fix
  757.     rm -f ${LIB}/$file
  758.     cp /tmp/$base ${LIB}/$file
  759.     chmod a+r ${LIB}/$file
  760.     rm -f /tmp/$base
  761.   fi
  762. fi
  763.  
  764. # Conditionalize all of <sys/err.h> on _KERNEL being defined.
  765.  
  766. file=sys/err.h
  767. base=`basename $file`
  768. if [ -r ${LIB}/$file ]; then
  769.   file_to_fix=${LIB}/$file
  770. else
  771.   if [ -r ${INPUT}/$file ]; then
  772.     file_to_fix=${INPUT}/$file
  773.   else
  774.     file_to_fix=""
  775.   fi
  776. fi
  777. if [ \! -z "$file_to_fix" ]; then
  778.   echo Checking $file_to_fix
  779.   if grep _KERNEL $file_to_fix > /dev/null; then
  780.     true
  781.   else
  782.     echo '#ifdef _KERNEL' > /tmp/$base
  783.     cat $file_to_fix >> /tmp/$base
  784.     echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
  785.     echo Fixed $file_to_fix
  786.     rm -f ${LIB}/$file
  787.     cp /tmp/$base ${LIB}/$file
  788.     chmod a+r ${LIB}/$file
  789.     rm -f /tmp/$base
  790.   fi
  791. fi
  792.  
  793. # Conditionalize all of <sys/char.h> on _KERNEL being defined.
  794.  
  795. file=sys/char.h
  796. base=`basename $file`
  797. if [ -r ${LIB}/$file ]; then
  798.   file_to_fix=${LIB}/$file
  799. else
  800.   if [ -r ${INPUT}/$file ]; then
  801.     file_to_fix=${INPUT}/$file
  802.   else
  803.     file_to_fix=""
  804.   fi
  805. fi
  806. if [ \! -z "$file_to_fix" ]; then
  807.   echo Checking $file_to_fix
  808.   if grep _KERNEL $file_to_fix > /dev/null; then
  809.     true
  810.   else
  811.     echo '#ifdef _KERNEL' > /tmp/$base
  812.     cat $file_to_fix >> /tmp/$base
  813.     echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
  814.     echo Fixed $file_to_fix
  815.     rm -f ${LIB}/$file
  816.     cp /tmp/$base ${LIB}/$file
  817.     chmod a+r ${LIB}/$file
  818.     rm -f /tmp/$base
  819.   fi
  820. fi
  821.  
  822. # Conditionalize all of <sys/getpages.h> on _KERNEL being defined.
  823.  
  824. file=sys/getpages.h
  825. base=`basename $file`
  826. if [ -r ${LIB}/$file ]; then
  827.   file_to_fix=${LIB}/$file
  828. else
  829.   if [ -r ${INPUT}/$file ]; then
  830.     file_to_fix=${INPUT}/$file
  831.   else
  832.     file_to_fix=""
  833.   fi
  834. fi
  835. if [ \! -z "$file_to_fix" ]; then
  836.   echo Checking $file_to_fix
  837.   if grep _KERNEL $file_to_fix > /dev/null; then
  838.     true
  839.   else
  840.     echo '#ifdef _KERNEL' > /tmp/$base
  841.     cat $file_to_fix >> /tmp/$base
  842.     echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
  843.     echo Fixed $file_to_fix
  844.     rm -f ${LIB}/$file
  845.     cp /tmp/$base ${LIB}/$file
  846.     chmod a+r ${LIB}/$file
  847.     rm -f /tmp/$base
  848.   fi
  849. fi
  850.  
  851. # Conditionalize all of <sys/map.h> on _KERNEL being defined.
  852.  
  853. file=sys/map.h
  854. base=`basename $file`
  855. if [ -r ${LIB}/$file ]; then
  856.   file_to_fix=${LIB}/$file
  857. else
  858.   if [ -r ${INPUT}/$file ]; then
  859.     file_to_fix=${INPUT}/$file
  860.   else
  861.     file_to_fix=""
  862.   fi
  863. fi
  864. if [ \! -z "$file_to_fix" ]; then
  865.   echo Checking $file_to_fix
  866.   if grep _KERNEL $file_to_fix > /dev/null; then
  867.     true
  868.   else
  869.     echo '#ifdef _KERNEL' > /tmp/$base
  870.     cat $file_to_fix >> /tmp/$base
  871.     echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
  872.     echo Fixed $file_to_fix
  873.     rm -f ${LIB}/$file
  874.     cp /tmp/$base ${LIB}/$file
  875.     chmod a+r ${LIB}/$file
  876.     rm -f /tmp/$base
  877.   fi
  878. fi
  879.  
  880. # Conditionalize all of <sys/cmn_err.h> on _KERNEL being defined.
  881.  
  882. file=sys/cmn_err.h
  883. base=`basename $file`
  884. if [ -r ${LIB}/$file ]; then
  885.   file_to_fix=${LIB}/$file
  886. else
  887.   if [ -r ${INPUT}/$file ]; then
  888.     file_to_fix=${INPUT}/$file
  889.   else
  890.     file_to_fix=""
  891.   fi
  892. fi
  893. if [ \! -z "$file_to_fix" ]; then
  894.   echo Checking $file_to_fix
  895.   if grep _KERNEL $file_to_fix > /dev/null; then
  896.     true
  897.   else
  898.     echo '#ifdef _KERNEL' > /tmp/$base
  899.     cat $file_to_fix >> /tmp/$base
  900.     echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
  901.     echo Fixed $file_to_fix
  902.     rm -f ${LIB}/$file
  903.     cp /tmp/$base ${LIB}/$file
  904.     chmod a+r ${LIB}/$file
  905.     rm -f /tmp/$base
  906.   fi
  907. fi
  908.  
  909. # Conditionalize all of <sys/kdebugger.h> on _KERNEL being defined.
  910.  
  911. file=sys/kdebugger.h
  912. base=`basename $file`
  913. if [ -r ${LIB}/$file ]; then
  914.   file_to_fix=${LIB}/$file
  915. else
  916.   if [ -r ${INPUT}/$file ]; then
  917.     file_to_fix=${INPUT}/$file
  918.   else
  919.     file_to_fix=""
  920.   fi
  921. fi
  922. if [ \! -z "$file_to_fix" ]; then
  923.   echo Checking $file_to_fix
  924.   if grep _KERNEL $file_to_fix > /dev/null; then
  925.     true
  926.   else
  927.     echo '#ifdef _KERNEL' > /tmp/$base
  928.     cat $file_to_fix >> /tmp/$base
  929.     echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
  930.     echo Fixed $file_to_fix
  931.     rm -f ${LIB}/$file
  932.     cp /tmp/$base ${LIB}/$file
  933.     chmod a+r ${LIB}/$file
  934.     rm -f /tmp/$base
  935.   fi
  936. fi
  937.  
  938. # Conditionalize some of <netinet/in.h> on _KERNEL being defined.
  939.  
  940. file=netinet/in.h
  941. base=`basename $file`
  942. if [ -r ${LIB}/$file ]; then
  943.   file_to_fix=${LIB}/$file
  944. else
  945.   if [ -r ${INPUT}/$file ]; then
  946.     file_to_fix=${INPUT}/$file
  947.   else
  948.     file_to_fix=""
  949.   fi
  950. fi
  951. if [ \! -z "$file_to_fix" ]; then
  952.   echo Checking $file_to_fix
  953.   if grep _KERNEL $file_to_fix > /dev/null; then
  954.     true
  955.   else
  956.     sed -e '/#ifdef INKERNEL/i\
  957. #ifdef _KERNEL' \
  958.     -e '/#endif[     ]*\/\* INKERNEL \*\//a\
  959. #endif /* _KERNEL */' \
  960.     $file_to_fix > ${LIB}/${file}.sed
  961.     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  962.     echo Fixed $file_to_fix
  963.   fi
  964. fi
  965.  
  966. # Conditionalize some of <sys/endian.h> on __GNUC__ and __GNUG__.
  967.  
  968. file=sys/endian.h
  969. base=`basename $file`
  970. if [ -r ${LIB}/$file ]; then
  971.   file_to_fix=${LIB}/$file
  972. else
  973.   if [ -r ${INPUT}/$file ]; then
  974.     file_to_fix=${INPUT}/$file
  975.   else
  976.     file_to_fix=""
  977.   fi
  978. fi
  979. if [ \! -z "$file_to_fix" ]; then
  980.   echo Checking $file_to_fix
  981.   if grep __GNUC__ $file_to_fix > /dev/null; then
  982.     true
  983.   else
  984.     sed -e '/#    ifdef    __STDC__/i\
  985. #   if !defined (__GNUC__) && !defined (__GNUG__)' \
  986.     -e '/#        include    <sys\/byteorder.h>/s/        /   /'\
  987.     -e '/#   include    <sys\/byteorder.h>/i\
  988. #   endif /* !defined (__GNUC__) && !defined (__GNUG__) */'\
  989.     $file_to_fix > ${LIB}/${file}.sed
  990.     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  991.     echo Fixed $file_to_fix
  992.   fi
  993. fi
  994.  
  995. # Commented out because tmcconne@sedona.intel.com says we don't clearly need it
  996. # and the text in types.h is not erroneous.
  997. ## In sys/types.h, don't name the enum for booleans.
  998. #
  999. #file=sys/types.h
  1000. #base=`basename $file`
  1001. #if [ -r ${LIB}/$file ]; then
  1002. #  file_to_fix=${LIB}/$file
  1003. #else
  1004. #  if [ -r ${INPUT}/$file ]; then
  1005. #    file_to_fix=${INPUT}/$file
  1006. #  else
  1007. #    file_to_fix=""
  1008. #  fi
  1009. #fi
  1010. #if [ \! -z "$file_to_fix" ]; then
  1011. #  echo Checking $file_to_fix
  1012. #  if grep "enum boolean" $file_to_fix > /dev/null; then
  1013. #    sed -e 's/enum boolean/enum/' ${LIB}/$file > ${LIB}/${file}.sed
  1014. #    rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1015. #    echo Fixed $file_to_fix
  1016. #  else
  1017. #    true
  1018. #  fi
  1019. #fi
  1020.  
  1021. # Remove useless extern keyword from struct forward declarations in
  1022. # <sys/stream.h> and <sys/strsubr.h>
  1023.  
  1024. file=sys/stream.h
  1025. base=`basename $file`
  1026. if [ -r ${LIB}/$file ]; then
  1027.   file_to_fix=${LIB}/$file
  1028. else
  1029.   if [ -r ${INPUT}/$file ]; then
  1030.     file_to_fix=${INPUT}/$file
  1031.   else
  1032.     file_to_fix=""
  1033.   fi
  1034. fi
  1035. if [ \! -z "$file_to_fix" ]; then
  1036.   echo Checking $file_to_fix
  1037.   sed -e '
  1038.     s/extern struct stdata;/struct stdata;/g
  1039.     s/extern struct strevent;/struct strevent;/g
  1040.   ' $file_to_fix > /tmp/$base 
  1041.   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
  1042.     true
  1043.   else
  1044.     echo Fixed $file_to_fix
  1045.     rm -f ${LIB}/$file
  1046.     cp /tmp/$base ${LIB}/$file
  1047.     chmod a+r ${LIB}/$file
  1048.   fi
  1049.   rm -f /tmp/$base
  1050. fi
  1051.  
  1052. file=sys/strsubr.h
  1053. base=`basename $file`
  1054. if [ -r ${LIB}/$file ]; then
  1055.   file_to_fix=${LIB}/$file
  1056. else
  1057.   if [ -r ${INPUT}/$file ]; then
  1058.     file_to_fix=${INPUT}/$file
  1059.   else
  1060.     file_to_fix=""
  1061.   fi
  1062. fi
  1063. if [ \! -z "$file_to_fix" ]; then
  1064.   echo Checking $file_to_fix
  1065.   sed -e '
  1066.     s/extern struct strbuf;/struct strbuf;/g
  1067.     s/extern struct uio;/struct uio;/g
  1068.     s/extern struct thread;/struct thread;/g
  1069.     s/extern struct proc;/struct proc;/g
  1070.   ' $file_to_fix > /tmp/$base 
  1071.   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
  1072.     true
  1073.   else
  1074.     echo Fixed $file_to_fix
  1075.     rm -f ${LIB}/$file
  1076.     cp /tmp/$base ${LIB}/$file
  1077.     chmod a+r ${LIB}/$file
  1078.   fi
  1079.   rm -f /tmp/$base
  1080. fi
  1081.  
  1082. # Put storage class at start of decl, to avoid warning.
  1083. file=rpc/types.h
  1084. base=`basename $file`
  1085. if [ -r ${LIB}/$file ]; then
  1086.   file_to_fix=${LIB}/$file
  1087. else
  1088.   if [ -r ${INPUT}/$file ]; then
  1089.     file_to_fix=${INPUT}/$file
  1090.   else
  1091.     file_to_fix=""
  1092.   fi
  1093. fi
  1094. if [ \! -z "$file_to_fix" ]; then
  1095.   echo Checking $file_to_fix
  1096.   sed -e '
  1097.     s/const extern/extern const/g
  1098.   ' $file_to_fix > /tmp/$base 
  1099.   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
  1100.     true
  1101.   else
  1102.     echo Fixed $file_to_fix
  1103.     rm -f ${LIB}/$file
  1104.     cp /tmp/$base ${LIB}/$file
  1105.     chmod a+r ${LIB}/$file
  1106.   fi
  1107.   rm -f /tmp/$base
  1108. fi
  1109.  
  1110. # Convert functions to prototype form, and fix arg names in <sys/stat.h>.
  1111.  
  1112. file=sys/stat.h
  1113. base=`basename $file`
  1114. if [ -r ${LIB}/$file ]; then
  1115.   file_to_fix=${LIB}/$file
  1116. else
  1117.   if [ -r ${INPUT}/$file ]; then
  1118.     file_to_fix=${INPUT}/$file
  1119.   else
  1120.     file_to_fix=""
  1121.   fi
  1122. fi
  1123. if [ \! -z "$file_to_fix" ]; then
  1124.   echo Checking $file_to_fix
  1125.   cp $file_to_fix /tmp/$base
  1126.   chmod +w /tmp/$base
  1127.   sed -e '/^stat([     ]*[^c]/{
  1128. N
  1129. N
  1130. s/(.*)\n/( /
  1131. s/;\n/, /
  1132. s/;$/)/
  1133. }' \
  1134.   -e '/^lstat([     ]*[^c]/{
  1135. N
  1136. N
  1137. s/(.*)\n/( /
  1138. s/;\n/, /
  1139. s/;$/)/
  1140. }' \
  1141.   -e '/^fstat([     ]*[^i]/{
  1142. N
  1143. N
  1144. s/(.*)\n/( /
  1145. s/;\n/, /
  1146. s/;$/)/
  1147. }' \
  1148.   -e '/^mknod([     ]*[^c]/{
  1149. N
  1150. N
  1151. N
  1152. s/(.*)\n/( /
  1153. s/;\n/, /g
  1154. s/;$/)/
  1155. }' \
  1156.   -e '1,$s/\([^A-Za-z]\)path\([^A-Za-z]\)/\1__path\2/g' \
  1157.   -e '1,$s/\([^A-Za-z]\)buf\([^A-Za-z]\)/\1__buf\2/g' \
  1158.   -e '1,$s/\([^A-Za-z]\)fd\([^A-Za-z]\)/\1__fd\2/g' \
  1159.   -e '1,$s/ret\([^u]\)/__ret\1/g' \
  1160.   -e '1,$s/\([^_]\)mode\([^_]\)/\1__mode\2/g' \
  1161.   -e '1,$s/\([^_r]\)dev\([^_]\)/\1__dev\2/g' /tmp/$base > /tmp/$base.sed
  1162.   if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
  1163.     true
  1164.   else
  1165.     echo Fixed $file_to_fix
  1166.     rm -f ${LIB}/$file
  1167.     cp /tmp/$base.sed ${LIB}/$file
  1168.     chmod a+r ${LIB}/$file
  1169.   fi
  1170.   rm -f /tmp/$base /tmp/$base.sed
  1171. fi
  1172.  
  1173. # Sony NEWSOS 5.0 does not support the complete ANSI C standard.
  1174.  
  1175. if [ -x /bin/sony ]; then
  1176.   if /bin/sony; then
  1177.  
  1178.     # Change <stdio.h> to not define __filbuf, __flsbuf, and __iob
  1179.  
  1180.     file=stdio.h
  1181.     base=`basename $file`
  1182.     if [ -r ${LIB}/$file ]; then
  1183.       file_to_fix=${LIB}/$file
  1184.     else
  1185.       if [ -r ${INPUT}/$file ]; then
  1186.         file_to_fix=${INPUT}/$file
  1187.       else
  1188.         file_to_fix=""
  1189.       fi
  1190.     fi
  1191.     if [ \! -z "$file_to_fix" ]; then
  1192.       echo Checking $file_to_fix
  1193.       cp $file_to_fix /tmp/$base
  1194.       chmod +w /tmp/$base
  1195.       sed -e '
  1196.         s/__filbuf/_filbuf/g
  1197.         s/__flsbuf/_flsbuf/g
  1198.         s/__iob/_iob/g
  1199.       ' /tmp/$base > /tmp/$base.sed
  1200.       mv /tmp/$base.sed /tmp/$base
  1201.       if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then
  1202.         true
  1203.       else
  1204.         echo Fixed $file_to_fix
  1205.         rm -f ${LIB}/$file
  1206.         cp /tmp/$base ${LIB}/$file
  1207.         chmod a+r ${LIB}/$file
  1208.       fi
  1209.       rm -f /tmp/$base
  1210.     fi
  1211.  
  1212.     # Change <ctype.h> to not define __ctype
  1213.  
  1214.     file=ctype.h
  1215.     base=`basename $file`
  1216.     if [ -r ${LIB}/$file ]; then
  1217.       file_to_fix=${LIB}/$file
  1218.     else
  1219.       if [ -r ${INPUT}/$file ]; then
  1220.         file_to_fix=${INPUT}/$file
  1221.       else
  1222.         file_to_fix=""
  1223.       fi
  1224.     fi
  1225.     if [ \! -z "$file_to_fix" ]; then
  1226.       echo Checking $file_to_fix
  1227.       cp $file_to_fix /tmp/$base
  1228.       chmod +w /tmp/$base
  1229.       sed -e '
  1230.         s/__ctype/_ctype/g
  1231.       ' /tmp/$base > /tmp/$base.sed
  1232.       mv /tmp/$base.sed /tmp/$base
  1233.       if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then
  1234.         true
  1235.       else
  1236.         echo Fixed $file_to_fix
  1237.         rm -f ${LIB}/$file
  1238.         cp /tmp/$base ${LIB}/$file
  1239.         chmod a+r ${LIB}/$file
  1240.       fi
  1241.       rm -f /tmp/$base
  1242.     fi
  1243.   fi
  1244. fi
  1245.  
  1246. # In limits.h, put #ifndefs around things that are supposed to be defined
  1247. # in float.h to avoid redefinition errors if float.h is included first.
  1248. # Solaris 2.1 has this problem.
  1249.  
  1250. file=limits.h
  1251. base=`basename $file`
  1252. if [ -r ${LIB}/$file ]; then
  1253.   file_to_fix=${LIB}/$file
  1254. else
  1255.   if [ -r ${INPUT}/$file ]; then
  1256.     file_to_fix=${INPUT}/$file
  1257.   else
  1258.     file_to_fix=""
  1259.   fi
  1260. fi
  1261. if [ \! -z "$file_to_fix" ]; then
  1262.   echo Checking $file_to_fix
  1263.   sed -e '/[     ]FLT_MIN[     ]/i\
  1264. #ifndef FLT_MIN'\
  1265.       -e '/[     ]FLT_MIN[     ]/a\
  1266. #endif'\
  1267.       -e '/[     ]FLT_MAX[     ]/i\
  1268. #ifndef FLT_MAX'\
  1269.       -e '/[     ]FLT_MAX[     ]/a\
  1270. #endif'\
  1271.       -e '/[     ]FLT_DIG[     ]/i\
  1272. #ifndef FLT_DIG'\
  1273.       -e '/[     ]FLT_DIG[     ]/a\
  1274. #endif'\
  1275.       -e '/[     ]DBL_MIN[     ]/i\
  1276. #ifndef DBL_MIN'\
  1277.       -e '/[     ]DBL_MIN[     ]/a\
  1278. #endif'\
  1279.       -e '/[     ]DBL_MAX[     ]/i\
  1280. #ifndef DBL_MAX'\
  1281.       -e '/[     ]DBL_MAX[     ]/a\
  1282. #endif'\
  1283.       -e '/[     ]DBL_DIG[     ]/i\
  1284. #ifndef DBL_DIG'\
  1285.       -e '/[     ]DBL_DIG[     ]/a\
  1286. #endif' $file_to_fix > /tmp/$base
  1287.   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
  1288.     true
  1289.   else
  1290.     echo Fixed $file_to_fix
  1291.     rm -f ${LIB}/$file
  1292.     cp /tmp/$base ${LIB}/$file
  1293.     chmod a+r ${LIB}/$file
  1294.   fi
  1295.   rm -f /tmp/$base
  1296. fi
  1297.  
  1298. # Completely replace <sys/varargs.h> with a file that includes gcc's
  1299. # stdarg.h or varargs.h files as appropriate.
  1300.  
  1301. file=sys/varargs.h
  1302. if [ -r ${INPUT}/$file ]; then
  1303.   echo Replacing $file
  1304.   cat > ${LIB}/$file << EOF
  1305. /* This file was generated by fixincludes.  */
  1306. #ifndef _SYS_VARARGS_H
  1307. #define _SYS_VARARGS_H
  1308.  
  1309. #ifdef __STDC__
  1310. #include <stdarg.h>
  1311. #else
  1312. #include <varargs.h>
  1313. #endif
  1314.  
  1315. #endif  /* _SYS_VARARGS_H */
  1316. EOF
  1317.   chmod a+r ${LIB}/$file
  1318. fi
  1319.  
  1320. # In math.h, put #ifndefs around things that might be defined in a gcc
  1321. # specific math-*.h file.
  1322.  
  1323. file=math.h
  1324. base=`basename $file`
  1325. if [ -r ${LIB}/$file ]; then
  1326.   file_to_fix=${LIB}/$file
  1327. else
  1328.   if [ -r ${INPUT}/$file ]; then
  1329.     file_to_fix=${INPUT}/$file
  1330.   else
  1331.     file_to_fix=""
  1332.   fi
  1333. fi
  1334. if [ \! -z "$file_to_fix" ]; then
  1335.   echo Checking $file_to_fix
  1336.   sed -e '/define[     ]HUGE_VAL[     ]/i\
  1337. #ifndef HUGE_VAL'\
  1338.       -e '/define[     ]HUGE_VAL[     ]/a\
  1339. #endif' $file_to_fix > /tmp/$base
  1340.   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
  1341.     true
  1342.   else
  1343.     echo Fixed $file_to_fix
  1344.     rm -f ${LIB}/$file
  1345.     cp /tmp/$base ${LIB}/$file
  1346.     chmod a+r ${LIB}/$file
  1347.   fi
  1348.   rm -f /tmp/$base
  1349. fi
  1350.  
  1351. echo 'Removing unneeded directories:'
  1352. cd $LIB
  1353. files=`find . -type d -print | sort -r`
  1354. for file in $files; do
  1355.   rmdir $LIB/$file > /dev/null 2>&1
  1356. done
  1357.  
  1358. if $LINKS; then
  1359.   echo 'Making internal symbolic non-directory links'
  1360.   cd ${INPUT}
  1361.   files=`find . -type l -print`
  1362.   for file in $files; do
  1363.     dest=`ls -ld $file | sed -n 's/.*-> //p'`
  1364.     if expr "$dest" : '[^/].*' > /dev/null; then    
  1365.       target=${LIB}/`echo file | sed "s|[^/]*\$|$dest|"`
  1366.       if [ -f $target ]; then
  1367.         ln -s $dest ${LIB}/$file >/dev/null 2>&1
  1368.       fi
  1369.     fi
  1370.   done
  1371. fi
  1372.  
  1373. cd ${ORIG_DIR}
  1374.  
  1375. echo 'Replacing <sys/byteorder.h>'
  1376. rm -f ${LIB}/sys/byteorder.h
  1377. cp ${SRCDIR}/byteorder.h ${LIB}/sys/byteorder.h
  1378.  
  1379. exit 0
  1380.  
  1381.